package com.atom.module.document.ui;

import android.view.View;

import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import java.util.HashMap;
import java.util.Map;

/**
 * All rights Reserved, Designed By www.rongdasoft.com
 *
 * @version V1.0
 * @Title: AbstractAppCompatActivity
 * @Description:
 * @author: wuyongzheng
 * @date: 2022/3/28
 * @Copyright: 2022/3/28 www.rongdasoft.com Inc. All rights reserved.
 */
public abstract class AbstractAppCompatActivity extends AppCompatActivity {


    //--------------------------------------
    final Map<Integer, View> views = new HashMap<>();

    interface PickView<T extends View> {
        void view(T t);
    }

    public <T extends View> void view(@IdRes int id, @NonNull PickView<T> pickView) {
        View view = views.get(id);
        if (view == null) {
            view = findViewById(id);
            views.put(id, view);
        }
        if (view == null) {
            throw new RuntimeException("can not find view by " + id);
        }
        pickView.view((T) view);
    }
}
